﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Windows.Input;

namespace Redboil.Bfp.Core {
    public class DelegateCommand : ICommand {
        public delegate void SimpleEventHandler(object sender, EventArgs e);
        private SimpleEventHandler handler;
        private bool isEnabled = true;
        public event EventHandler CanExecuteChanged;

        public bool IsEnabled {
            get { return this.isEnabled; }
            set {
                this.isEnabled = value;
                this.OnCanExecuteChanged();
            }
        }

        public DelegateCommand(SimpleEventHandler handler) {
            this.handler = handler;
        }

        private void OnCanExecuteChanged() {
            if(this.CanExecuteChanged != null) {
                this.CanExecuteChanged(this, EventArgs.Empty);
            }
        }

        public void Execute(object parameter) {
            this.handler(this, EventArgs.Empty);
        }

        public bool CanExecute(object parameter) {
            return this.IsEnabled;
        }
    }
}
